package com.example.cuibo.myapplicationlistview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 找到相关的控件
        ListView listview = (ListView) findViewById(R.id.lv);
        // 设置lv的适配
        listview.setAdapter(new Myadapter());
    }
    private class Myadapter extends BaseAdapter{
        @Override
        public int getCount() {
            return 6;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView tv;
            if(view == null){
                tv = new TextView(MainActivity.this);
            }else {
                tv = (TextView) view;
            }
            tv.setText("嘿嘿");
            return tv;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public Object getItem(int i) {

            return  null;
        }
    }
}
